package com.leetcode.sort.basic_sort;

import java.util.Random;

/**
 * @author Dennis Li
 * @date 2020/9/9 23:43
 */
public class SelectSort extends Sort{

    public static void main(String[] args) {
        int[] res = new Random().ints(10, 0, 100).toArray();
        sort2(res);
        System.out.println(isSorted(res));
    }

    public static void sort(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            int min = i;
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[j] < arr[min])
                    min = j;
            }
            swap(arr, i, min);
        }
    }

    public static void sort2(int[] arr){
        int len = arr.length;
        for (int i = 0; i < len; i++) {
            int min = i;
            for (int j = i + 1; j < len; j++) {
                if (arr[j] < arr[min]) {
                    min = j;
                }
            }
            swap(arr, i, min);
        }
    }

}
